package com.example.base.cons

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

object RetFitUtils {
    fun retrofit():Retrofit{
        val client = OkHttpClient.Builder()
            .writeTimeout(5, TimeUnit.SECONDS)
            .connectTimeout(5, TimeUnit.SECONDS)
            .readTimeout(5, TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor {
                val newBuilder = it.request().newBuilder()
                newBuilder.addHeader("accessId", "e85d293803a745d59d457da73969fe63")
                newBuilder.addHeader("token", Cons.Token)
                it.proceed(newBuilder.build())
            }
            .build()

        val retrofit = Retrofit.Builder()
            .client(client)
            .baseUrl(Cons.BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
        return retrofit
    }
}